package zdsmj;

import java.util.Scanner;

public class MoneyCounter {
    public int getTotal() {//会员卡结算
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    private int total;
    public void Cal(int Price,int total){
        Scanner in = new Scanner(System.in);
        int totalPay=0;
        if(total>=Price){
            totalPay=total;
        }else if(total<Price){
            System.out.println("请投币..."); //投入硬币
            int inPay= in.nextInt();
            totalPay=inPay+total;
        }

        if(totalPay==Price) {
        //调用 Equal 方法
            Equal();
        }
        else if(totalPay>Price) {
 //调用 More 方法
            More(Price,totalPay);
        }
        else {
            for(int i=0;totalPay<Price;i++){
//当投入金额小于饮品价格时，提示继续投币
                Scanner input = new Scanner(System.in);
                System.out.println("请继续投币...");
                int everyPay = input.nextInt();
                totalPay+=everyPay;
            }
            if(totalPay==Price) { //当再次投币出现投币金额=价格时，调用 Equal 方法
Equal();
            }
            else{
More(Price,totalPay);
            }//当再次投币出现投币金额>价格时，调用 More 方法
        }
    }
    public void Equal() { //当投入硬币和价格相同时
        System.out.println("请在出口处取饮料，找零为0元");
        System.out.println("1元：0枚");
        System.out.println("5元：0枚");
        System.out.println("10元：0枚");
        System.out.println("20元：0枚");
        System.out.println("50元：0枚");
        System.out.println("100元：0枚");
        System.out.println("bye-bye,欢迎下次购买...");
    }
    public void More(int Price,int totalPay){ //当投入硬币总数大于价格总数时
        int Blance=totalPay-Price;
        System.out.println("请在出口处取饮料，找零为"+Blance+"元,分别为");
        //分钱
        int[] mon={100,50,20,10,5,1};
        int[] mon1=new int[6];
        for (int i = 0; i <mon.length ; i++) {
            mon1[i]=Blance/mon[i];
            Blance=Blance-mon1[i]*mon[i];
            System.out.println(mon[i]+"元："+mon1[i]+"枚");
            
        }
        System.out.println("bye-bye,欢迎下次购买...");









    }
}
